#include <REGX52.H>

#include "OneWire.h"

#define DS18B20_SKIP_ROM    0xCC
#define DS18N20_CONVERT_T   0x44
#define DS18B20_READ_SCRATCHPAD     0xBE

/*
* Parameter		:
* ReturnValue	:
* Function		:
* Date			:2023-11-11 20:39:56
*/
void DS18B20_ConvertT(void){

   OneWire_Init();
   OneWire_SendByte(DS18B20_SKIP_ROM);
   OneWire_SendByte(DS18N20_CONVERT_T);
}

/*
* Parameter		:
* ReturnValue	:
* Function		:read temperature 
* Date			:2023-11-11 21:38:37
*/
float DS18B20_ReadT(void){
    unsigned char TLSB,TMSB;
    int Temp;
    float T;
    OneWire_Init();
    OneWire_SendByte(DS18B20_SKIP_ROM);
    OneWire_SendByte(DS18B20_READ_SCRATCHPAD);
    TLSB=OneWire_ReceiveByte();
    TMSB=OneWire_ReceiveByte();
    Temp=(TMSB<<8)|TLSB;
    T=Temp/16.0;
    return T;
}